<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col>
      <strong v-if="isCompany">{{ nodeData.name }}</strong>
      <span v-else>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDeptFn">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="editDeptFn">编辑子部分</el-dropdown-item>
              <el-dropdown-item v-if="!isCompany" @click.native="delDeptFn">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { delDepts } from '@/api/departments'
export default {
  name: '',
  components: {},
  props: {
    nodeData: {
      type: Object,
      required: true// 表示必传值
    },
    isCompany: {
      type: Boolean,
      default: false// 表示默认值
    }
  },
  data() {
    return {}
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
  },
  methods: {
    // 新增数据
    addDeptFn() {
      // console.log(1234)
      this.$emit('addDept', this.nodeData)
    },
    // 删除数据
    async  delDeptFn() {
      // console.log(456)
      // 二次询问是否需要删除数据
      await this.$confirm('是否确认删除数据')
      // this.$emit('delDept',)
      // 发送亲求删除数据
      await delDepts(this.nodeData.id)
      // 提示用户
      this.$message.success('删除成功')
      // 更新页面
      this.$emit('updataDeptData')
    },
    // 编辑数据
    editDeptFn() {
      // 通知父组件将弹窗弹起来
      this.$emit('editDept', this.nodeData)
    }
  }
}
</script>
<style scoped lang='less'>
</style>
